<!--
描述：排重检测信息组件
开发人：hqj
开发日期：2018年12月07日
修改人：
修改日期：
-->
<template lang="pug">
    div.kalix-article(v-if="pageShow")
        div.frame-header
            div.frame-header--cnt
                el-form(ref="searchForm" v-bind:model="formModel" v-bind:inline="true" v-on:submit.native.prevent="")
                    el-form-item(label="题型" prop="questionType" v-bind:rules="rules.questionType" label-width="65px")
                        kalix-dict-select(v-model="formModel.questionType" appName="enrolment" dictType="题型" v-on:dictSelected="dictSelected")
                    el-form-item(v-if="formModel.questionType === '5'" label="题型子类" prop="subType" label-width="75px")
                        kalix-dict-select(v-model="formModel.subType" appName="enrolment" dictType="主观题类型")
                    el-form-item(v-if="formModel.questionType === '6'" label="题型子类" prop="subType" label-width="75px")
                        kalix-dict-select(v-model="formModel.subType" appName="enrolment" dictType="面试题类型")
                    el-form-item
                        el-button(type="success" v-on:click="onQueryClick")
                            i.iconfont.icon-query
                            | 查询
                        el-button(type="primary" v-on:click="onResetClick")
                            i.iconfont.icon-reset
                            | 重置
        div.frame-article
            div.frame-item
                keep-alive
                    kalix-table(bizKey="repeatedTesting" title='排重检测信息列表' v-bind:targetURL="repeatedTestingURL"
                    v-bind:toolbarBtnList="toolbarBtnList" v-bind:isShowPagination="false" ref="kalixTable")
                        template(slot="tableColumnSlot")
                            el-table-column(prop="questionTypeName" label="题型" align="center" width="150px")
                            el-table-column(prop="subTypeName" label="题型子类" align="center" width="150px")
                            el-table-column(prop="repeatedCount" label="重复数量" align="center" width="150px")
                            el-table-column(prop="stem" label="题干" align="center")
                                template(slot-scope="scope")
                                    el-popover(trigger="hover" placement="top" width="350")
                                        | {{scope.row.stem}}
                                        div(slot="reference")
                                            template(v-if="scope.row.stem && scope.row.stem.length > 20")
                                                | {{scope.row.stem.substr(0, 20)}}...
                                            template(v-else)
                                                | {{scope.row.stem}}
    div(v-else) 题库功能已关闭，如需使用请联系管理员！
</template>

<script type="text/ecmascript-6">
    import FormModel from './model'
    import {RepeatedTestingURL} from '../../config.toml'
    /*import {availableQuestion} from '../../common.js'*/

    export default {
        name: 'kalix-enrolment-repeatedtesting',
        data() {
            return {
                pageShow: false,
                formModel: Object.assign({}, FormModel),
                rules: {
                    questionType: [{required: true, message: '请选择题型', trigger: 'change'}]
                },
                toolbarBtnList: [
                    {id: 'add', isShow: false}
                ],
                repeatedTestingURL: RepeatedTestingURL
            }
        },
        components: {},
        created() {
            /*availableQuestion(this.axios, this.$KalixMessage, flag => {
             this.pageShow = flag
             })*/
            this.pageShow = true
        },
        mounted() {
        },
        computed: {},
        methods: {
            dictSelected(dict) {
                this.formModel.subType = ''
            },
            // 查询
            onQueryClick() {
                this.$refs.searchForm.validate((valid) => {
                    if (valid) {
                        this.clearTableData(0)
                        let queryCondition = {}
                        queryCondition['questionType'] = this.formModel.questionType
                        if (this.formModel.subType && this.formModel.subType.length) {
                            queryCondition['subType'] = this.formModel.subType
                        }
                        let jsonStr = JSON.stringify(queryCondition)
                        let searchObjAll = {jsonStr: jsonStr}
                        this.$KalixEventBus.$emit(this.$KalixEventConfig.ON_SEARCH_BUTTON_CLICK, searchObjAll)
                    } else {
                        this.$KalixMessage.error('请检查输入项！')
                        return
                    }
                })
            },
            // 重置搜索框
            onResetClick() {
                this.$refs.searchForm.resetFields()
                this.clearTableData(0)
            },
            // 清除列表数据0全部
            clearTableData(num) {
                switch (num) {
                    // 清除所有列表数据
                    case 0 :
                        this.$refs.kalixTable.clearData()
                        break
                    default :
                        this.$refs.kalixTable.clearData()
                        break
                }
            }
        }
    }
</script>

<style scoped lang="stylus">
    .frame-header
        background-color rgb(255, 255, 255)
        padding-top 7px
        margin-bottom 7px

    .frame-article
        flex 1
        display flex
        flex-direction column
        .frame-article--split
            height 7px
        .frame-item
            flex 1
</style>
